/*
 * ExtTableOT.java
 *
 * $Id: ExtTableOT.java,v 1.1 2008-03-18 12:58:45 mario Exp $
 *
 * Written by: Mario García García <mario@imagos.es>
 * (c) 2007 Fundación Centro Tecnológico de la Carne
 * 
 */
package org.ceteca.explica.core.extTables;

import java.io.Serializable;
import java.util.Map;

/**
 * Store class to hold the data of the extended table. It keeps the metadata and
 * the values of the extension fields defined for an extended item.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Store of extension data for exchanging data among presentation, 
 * business and data access layers. </ul>
 * </li>
 */
public class ExtTableOT implements Serializable {
	/**
	 * Map to store an undefined number of extension field values.
	 */
	private Map fieldValues;
	/**
	 * Internal Id of the extension table.
	 */
	private long idExtTable;
	/**
	 * Code key of the extension table.
	 */
	private String codExtTable;
	/**
	 * Name of the extension table.
	 */
	private String tableDescription;
	/**
	 * Name of the id field in the original table (extended table id).
	 */
	private String idFieldName;
	/**
	 * Value of the id field in the original table (extended table id). It's the 
	 * id value of the extended item.
	 */
	private long idItem;
	
	private static final long serialVersionUID = 10000001;
	
	private Integer version = new Integer(0);
	
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
	
	public ExtTableOT() {
	}
	
	public String getTableDescription() {
		return tableDescription;
	}

	public void setTableDescription(String tableDescription) {
		this.tableDescription = tableDescription;
	}

	public Map getFieldValues() {
		return fieldValues;
	}

	public void setFieldValues(Map fieldValues) {
		this.fieldValues = fieldValues;
	}

	public long getIdExtTable() {
		return idExtTable;
	}

	public void setIdExtTable(long idExtTable) {
		this.idExtTable = idExtTable;
	}
	
	public String getCodExtTable() {
		return codExtTable;
	}

	public void setCodExtTable(String codExtTable) {
		this.codExtTable = codExtTable;
	}

	public String getIdFieldName() {
		return idFieldName;
	}

	public void setIdFieldName(String idFieldName) {
		this.idFieldName = idFieldName;
	}

	public long getIdItem() {
		return idItem;
	}

	public void setIdItem(long idItem) {
		this.idItem = idItem;
	}
	
	public boolean equals(Object other) {
        if (this == other) 
        	return true;
        if ( !(other instanceof ExtTableOT) ) 
        	return false;

        final ExtTableOT extTab = (ExtTableOT) other;

        if ( extTab.getCodExtTable() == null )
        	return this.getCodExtTable() == null;
        else if ( !extTab.getCodExtTable().equals( this.getCodExtTable() ) ) 
        	return false;

        return true;
    }

    public int hashCode() {
        int result;
        if (this == null || this.getCodExtTable() == null)
        	result = 0;
        else
        	result = this.getCodExtTable().hashCode();
        return result;
    }
    
    /**
	 * Implementation of the toString() method to show the data of the ExtFieldOT
	 * formatted.
	 */
	public String toString() {
		StringBuffer result = new StringBuffer();
		try {
			result.append("--- . --- . --- . --- . --- . --- . --- . ---\n");
			result.append("\nID: ");
			result.append(this.idExtTable);
			result.append("\nCODE: ");
			result.append(this.codExtTable);
			result.append("\nDESCRIPTION: ");
			result.append(this.tableDescription);
			result.append("\nID_FIELD: ");
			result.append(this.idFieldName);
			result.append("\nID_ITEM: ");
			result.append(this.idItem);
			result.append("\nFIELD_VALUES: ");
			result.append("\n### . ### . ### . ### . ### . ### . ### . ###");
			result.append(this.fieldValues);
			result.append("\n### . ### . ### . ### . ### . ### . ### . ###");
			result.append("\n\n--- . --- . --- . --- . --- . --- . --- . ---");
		}
		catch (Exception ex) {
			System.out.println("Error formatting ExtensionTableOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}
	
	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: ExtTableOT.java,v 1.1 2008-03-18 12:58:45 mario Exp $";
	}
}